﻿'###############################
'数据集的操作类
'作者：王永胜
'做成日期:
'################################
Imports System.Data.OleDb
Imports System.Reflection

Public Class CTable

#Region "类的成员变量"
    'Public Shared cdbXSC As New CDB   'D-2009-10-11
    Public cdbXSC As CDB = Nothing
    'Private Shared cdbXSC1 As CDB    'D-2009-07-11
    'Private cException As Object   '保存异常类 'D-2009-10-11
#End Region

#Region "构造函数类"
    Public Sub New()
        MyBase.New()
        'Me.cdbXSC = GetCn()
        'cException = GetException() 'D-2009-10-11
        cdbXSC = CDB.Instance 'A-2009-07-11
    End Sub
#End Region

#Region "该类为单例模式 A-2009-10-11"
    Private Shared _instance As CTable = Nothing
    Private Shared ReadOnly padlock As New Object
    Public Shared ReadOnly Property Instance() As CTable
        Get
            'Lock(padlock)
            If _instance Is Nothing Then
                _instance = New CTable
            End If
            'Unlock(padlock)
            Return _instance
        End Get
    End Property
#End Region

#Region "保存异常 D-2009-10-11"
    'Public Sub SaveException(ByVal e As Exception)
    '    'Dim strPath As String
    '    'strPath = System.Configuration.ConfigurationManager.AppSettings("ExceptionFile")
    '    'Dim sw As System.IO.StreamWriter
    '    'If (Not (System.IO.File.Exists(strPath))) Then
    '    '    sw = System.IO.File.CreateText(strPath)
    '    'End If

    '    'sw = New System.IO.StreamWriter(strPath, True)
    '    'If sw IsNot Nothing Then
    '    '    sw.WriteLine(e.ToString())
    '    '    sw.Close()
    '    'End If
    '    If cException Is Nothing Then
    '        cException = GetException()
    '    End If
    '    cException.SaveExcetpion(e)
    'End Sub

#End Region

#Region "得到数据库链接对象 D-2009-09-10"
    '    Public Function GetCn() As CDB
    '        If cdbXSC1 IsNot Nothing Then
    '            Return cdbXSC1
    '        End If
    '        GetCn = Nothing
    '        Try
    '            cdbXSC1 = New CDB()
    '            GetCn = cdbXSC1
    '        Catch ex As Exception
    '            SaveException(ex)
    '        End Try
    '    End Function
#End Region

#Region "得到记录集"
    Public Function GetTable(ByVal strSql As String) As ADODB.Recordset
        GetTable = Nothing
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            Dim rs As ADODB.Recordset
            rs = cn.Execute(strSql)
            GetTable = rs
        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function
#End Region

#Region "查询记录判断是否行锁,加的是共享锁"
    ''' <summary>
    ''' 查询记录判断是否行锁,加的是共享锁
    ''' </summary>
    ''' <param name="strSql">要查询的SQL</param>
    ''' <param name="bLock">为真时加共享锁，假时不加锁</param>
    ''' <returns>返回的是一个记录集</returns>
    ''' <remarks></remarks>
    Public Function GetTable(ByVal strSql As String, ByVal bLock As Boolean) As ADODB.Recordset
        GetTable = Nothing
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            Dim rs As New ADODB.Recordset
            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
            rs.Open(strSql, cn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockReadOnly)
            GetTable = rs
        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function
#End Region

#Region "得到当前登录用户的中文名称"
    Public Function GetUserName(ByVal strUsername As String) As String
        GetUserName = ""
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Close()
            End If
            Dim rs As ADODB.Recordset
            rs = cn.Execute("select * from XSCUSER where USERNAME='" + strUsername + "'")
            If rs.EOF Then
                rs.Close()
                cn.Close()
            Else
                GetUserName = CStr(rs.Fields("CHINESENAME").Value)
            End If
            Exit Function
        Catch ex As Exception
            'SaveException(ex) 'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function
#End Region

#Region "得到更新记录集"
    ''' <summary>
    ''' 得到更新记录集
    ''' </summary>
    ''' <param name="strSql"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetUpdateRs(ByVal strSql As String) As ADODB.Recordset
        GetUpdateRs = Nothing
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn
            Dim rs As New ADODB.Recordset
            'rs.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
            rs.CursorType = ADODB.CursorTypeEnum.adOpenDynamic
            rs.LockType = ADODB.LockTypeEnum.adLockOptimistic
            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
            rs.Open(strSql, cn)
            GetUpdateRs = rs
        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function
#End Region

#Region "得到能翻页的记录集"
    ''' <summary>
    ''' 得到能翻页的记录集
    ''' </summary>
    ''' <param name="strSql"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetUpdatePageRs(ByVal strSql As String) As ADODB.Recordset
        GetUpdatePageRs = Nothing
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn
            Dim rs As New ADODB.Recordset
            rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
            ' rs.LockType = ADODB.LockTypeEnum.adLockReadOnly //2009-07-21
            rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
            rs.Open(strSql, cn)
            GetUpdatePageRs = rs
        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function
#End Region

#Region "SQL是否存在"
    ''' <summary>
    ''' SQL是否存在
    ''' </summary>
    ''' <param name="strSql">要验证的SQL语句</param>
    ''' <returns>如果存在返回为真</returns>
    ''' <remarks></remarks>
    Public Function GetExistSql(ByVal strSql As String) As Boolean
        GetExistSql = False
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            Dim rs As ADODB.Recordset
            rs = cn.Execute(strSql)
            If rs IsNot Nothing Then
                If rs.EOF = False Then
                    rs.Close()
                    GetExistSql = True
                End If
            End If
            rs = Nothing
            Exit Function
        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function

#End Region

#Region "得到异常类 D-2009-10-11"
    '''' <summary>
    '''' 得到异常处理类
    '''' </summary>
    '''' <returns></returns>
    '''' <remarks></remarks>
    'Private Function GetException() As Object
    '    GetException = Nothing
    '    Dim strd1 As String
    '    Dim strName As String
    '    strd1 = System.Configuration.ConfigurationManager.AppSettings("DLLUTILDIRECTORY")
    '    '表示当前程序目录 2009-09-05
    '    If strd1 = "\" Then
    '        strd1 = System.IO.Directory.GetCurrentDirectory()
    '    End If
    '    '表示当前程序目录 2009-09-05
    '    strName = System.Configuration.ConfigurationManager.AppSettings("DLLUTILNAME")
    '    Dim strPath As String
    '    strPath = strd1 + "\" + strName
    '    If (System.IO.File.Exists(strPath)) Then
    '        Dim tempas As System.Reflection.Assembly
    '        tempas = System.Reflection.Assembly.LoadFile(strPath)

    '        Dim ty As System.Type = tempas.GetType("UTIL.CException")
    '        '创建实例
    '        GetException = System.Activator.CreateInstance(ty)
    '    End If
    'End Function
#End Region
    '2009-07-20
#Region "执行命令类"
    Public Function ExcCommand(ByVal cmd As ADODB.Command) As Boolean
        ExcCommand = False
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            cmd.ActiveConnection = cn
            cmd.Execute()
            ExcCommand = True
        Catch ex As Exception
            'SaveException(ex) 'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function
    '2009-07-26
    Public Function ExcCommandAsRs(ByVal cmd As ADODB.Command) As ADODB.Recordset
        ExcCommandAsRs = Nothing
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            cmd.ActiveConnection = cn
            ExcCommandAsRs = cmd.Execute()
        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
        '2009-07-26
    End Function
#End Region
    '2009-07-20
#Region "根据记录集填充表"
    Public Function FillTable(ByVal rs As ADODB.Recordset) As DataTable
        Dim dt As New DataTable
        Try
            Dim oleAda As New OleDb.OleDbDataAdapter
            oleAda.Fill(dt, rs)
        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
        FillTable = dt
    End Function

    Public Function FillTable(ByVal strSql As String) As DataTable
        Dim dt As New DataTable
        Try
            Dim rs As ADODB.Recordset = GetTable(strSql)
            Dim oleAda As New OleDb.OleDbDataAdapter
            oleAda.Fill(dt, rs)

        Catch ex As Exception
            'SaveException(ex)'D-2009-10-11
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
        FillTable = dt
    End Function
#End Region

#Region "得到数据库文件路径 A-2009-09-10"
    Public Shared Function GetDatabasePath() As String
        GetDatabasePath = ""
        GetDatabasePath = System.IO.Path.Combine(GetCurrentDirectory, "SQLITEDATA\XSC.db")
    End Function
#End Region

#Region "得到当前的目录 2009-09-10"
    Public Shared Function GetCurrentDirectory() As String
        GetCurrentDirectory = ""
        GetCurrentDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
        If GetCurrentDirectory.EndsWith("\\") Or GetCurrentDirectory.EndsWith("/") Then
            GetCurrentDirectory = GetCurrentDirectory.Substring(0, GetCurrentDirectory.Length - 1)
        End If
    End Function
#End Region

#Region "关闭所有链接 A-2009-09-13"
    'Public Shared Sub CloseAllDb()
    '    If cdbXSC IsNot Nothing Then
    '        cdbXSC.CloseCn()
    '    End If
    'End Sub
    Public Sub CloseAllDb()
        If cdbXSC IsNot Nothing Then
            cdbXSC.CloseCn()
        End If
    End Sub
#End Region

#Region "查询表的最大的ID号 A-2009-11-01 这个是插入窗口用的"
    Public Function GetMaxIdInsertForm(ByVal tableName As String) As Integer
        GetMaxIdInsertForm = 0
        Try
            Dim strSql As String = "select max(id) as ID FROM " + tableName
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            Dim rs As ADODB.Recordset
            rs = cn.Execute(strSql)
            If rs IsNot Nothing Then
                If rs.EOF = False Then
                    GetMaxIdInsertForm = CType(rs.Fields("ID").Value.ToString, Integer)
                    rs.Close()
                End If
            End If
        Catch ex As Exception
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try

    End Function
#End Region

#Region "最后一次更新的ID号 A-2009-11-01 这个是插入窗口用的"
    'Public Function GetMaxIdInsertForm(ByVal tableName As String) As Integer
    '    GetMaxIdInsertForm = 0
    '    Try
    '        Dim strSql As String = "select max(id) as ID FROM " + tableName
    '        Dim cn As ADODB.Connection
    '        cn = cdbXSC.GetCn()
    '        If cn Is Nothing Then Exit Function
    '        If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
    '            cn.Open()
    '        End If
    '        Dim rs As ADODB.Recordset
    '        rs = cn.Execute(strSql)
    '        If rs IsNot Nothing Then
    '            If rs.EOF = False Then
    '                GetMaxIdInsertForm = CType(rs.Fields("ID").Value.ToString, Integer)
    '                rs.Close()
    '            End If
    '        End If
    '    Catch ex As Exception
    '        UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
    '    End Try

    'End Function
#End Region

#Region "获取更新番号 A-2009-11-14"
    Public Enum TableType
        英语报表
        日语报表
    End Enum

    Public Function GetMax番号(ByVal ty As TableType) As Integer
        GetMax番号 = 0
        Try
            Dim strSql As String = "select content as 番号 FROM XSC连番"
            If ty = TableType.英语报表 Then
                strSql = strSql + " where TypeName='英语报表'"
            ElseIf ty = TableType.日语报表 Then
                strSql = strSql + " where TypeName='日语报表'"
            End If
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            Dim rs As ADODB.Recordset
            rs = cn.Execute(strSql)
            If rs IsNot Nothing Then
                If rs.EOF = False Then
                    GetMax番号 = CType(rs.Fields("番号").Value.ToString, Integer)
                    rs.Close()
                End If
            End If
        Catch ex As Exception
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function

    Public Sub Update番号(ByVal ty As TableType)
        Try
            Dim strSql As String = "update XSC连番 set content =content+1 "
            If ty = TableType.英语报表 Then
                strSql = strSql + " where TypeName='英语报表'"
            ElseIf ty = TableType.日语报表 Then
                strSql = strSql + " where TypeName='日语报表'"
            End If
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Sub
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            cn.Execute(strSql)
        Catch ex As Exception
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Sub

#End Region

#Region "A2009-12-13 根据一个ID获取所有的副窗体"
    ''' <summary>
    ''' GetParentName("12","XscBugType","Name","ParentID","ID")
    ''' </summary>
    ''' <param name="strId">查询的主键</param>
    ''' <param name="strTableName">表名</param>
    ''' <param name="strDisplayName">显示的名称</param>
    ''' <param name="strParent">父字段名称</param>
    ''' <param name="strChild">子字段名称</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetParentName(ByVal strId As String, ByVal strTableName As String, ByVal strDisplayName As String, ByVal strParent As String, ByVal strChild As String) As String
        GetParentName = ""
        Dim sb As New Text.StringBuilder
        sb.Append(" select ")
        sb.Append(strDisplayName + ",")
        sb.Append(strChild + ",")
        sb.Append(strParent)
        sb.Append(" from " + strTableName)
        sb.Append(" where " + strChild + "='" + strId + "'")
        Dim rs As ADODB.Recordset = GetTable(sb.ToString())
        If rs Is Nothing Then Exit Function
        If rs.EOF Then rs.Close() : Exit Function
        Do
            GetParentName = UTIL.CUtil.ConvertText(rs.Fields(strDisplayName).Value) + "/" + GetParentName
            sb = New Text.StringBuilder
            sb.Append(" select ")
            sb.Append(strDisplayName + ",")
            sb.Append(strChild + ",")
            sb.Append(strParent)
            sb.Append(" from " + strTableName)
            sb.Append(" where " + strChild + "='" + UTIL.CUtil.ConvertText(rs.Fields(strParent).Value) + "'")
            rs = GetTable(sb.ToString())
            If rs Is Nothing Then Exit Do
            If rs.EOF Then rs.Close() : Exit Do
        Loop Until (UTIL.CUtil.ConvertText(rs.Fields(strParent)) = "")

    End Function

    ''' <summary>
    ''' GetParentName("12","XscBugType","Name","ParentID","ID")
    ''' </summary>
    ''' <param name="strId">查询的主键</param>
    ''' <param name="strTableName">表名</param>
    ''' <param name="strDisplayName">显示的名称</param>
    ''' <param name="strParent">父字段名称</param>
    ''' <param name="strChild">子字段名称</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetParentName(ByVal strId As String, ByVal strTableName As String, ByVal strDisplayName As String, _
                                  ByVal strParent As String, ByVal strChild As String, _
                                  ByRef name As String, _
                                  ByRef memo As String) As String
        GetParentName = ""
        Dim sb As New Text.StringBuilder
        sb.Append(" select ")
        sb.Append(strDisplayName + ",")
        sb.Append(strChild + ",")
        sb.Append(strParent)
        sb.Append(",Memo")

        sb.Append(" from " + strTableName)
        sb.Append(" where " + strChild + "='" + strId + "'")
        Dim rs As ADODB.Recordset = GetTable(sb.ToString())
        If rs Is Nothing Then Exit Function
        If rs.EOF Then rs.Close() : Exit Function
        memo = UTIL.CUtil.ConvertText(rs.Fields("memo").Value)
        name = UTIL.CUtil.ConvertText(rs.Fields("name").Value)

        Do
            GetParentName = UTIL.CUtil.ConvertText(rs.Fields(strDisplayName).Value) + "/" + GetParentName
            sb = New Text.StringBuilder
            sb.Append(" select ")
            sb.Append(strDisplayName + ",")
            sb.Append(strChild + ",")
            sb.Append(strParent)
            sb.Append(" from " + strTableName)
            sb.Append(" where " + strChild + "='" + UTIL.CUtil.ConvertText(rs.Fields(strParent).Value) + "'")
            rs = GetTable(sb.ToString())
            If rs Is Nothing Then Exit Do
            If rs.EOF Then rs.Close() : Exit Do
        Loop Until (UTIL.CUtil.ConvertText(rs.Fields(strParent)) = "")

    End Function

#End Region

#Region "查询SQL A-2009-12-13"
    Public Function ExecuteSql(ByVal strSql As String) As ADODB.Recordset
        ExecuteSql = Nothing
        Try
            Dim cn As ADODB.Connection
            cn = cdbXSC.GetCn()
            If cn Is Nothing Then Exit Function
            If cn.State = ADODB.ObjectStateEnum.adStateClosed Then
                cn.Open()
            End If
            ExecuteSql = cn.Execute(strSql)
        Catch ex As Exception
            UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, ex, MethodBase.GetCurrentMethod.GetType()) 'A-2009-10-11
        End Try
    End Function
#End Region

#Region "根据父ID 查询子ID A-2010-1-2"
    Public Function GetChildIdAndSelf(ByVal strParentId As String, ByVal type As String) As List(Of String)
        Dim lst As New List(Of String)

        If (Not lst.Contains(strParentId)) Then
            lst.Add(strParentId)
        End If

        Dim rs As ADODB.Recordset = Nothing
        If (Not String.IsNullOrEmpty(strParentId)) Then
            rs = GetTable("select ID from XscBugType where ParentID='" + strParentId + "'")
        Else
            rs = GetTable("select ID from XscBugType where ParentID is null and type='" + type + "'")
        End If

        If rs Is Nothing Then
            GoTo Function_End
        End If

        If rs.EOF Then
            rs.Close()
            rs = Nothing
            GoTo Function_End
        End If

        Dim str As String = ""
        While Not rs.EOF
            str = rs.Fields("ID").Value.ToString()
            If Not (lst.Contains(str)) Then
                lst.Add(str)
            End If

            Dim resultChid As List(Of String) = GetChildIdAndSelf(str, type)
            If resultChid.Count = 0 Then
                GoTo While_Next
            End If

            For Each str2 As String In resultChid
                If Not lst.Contains(str2) Then
                    lst.Add(str2)
                End If
            Next
While_Next:
            rs.MoveNext()
        End While

Function_End:
        Return lst
    End Function
    'private static String[] GetChildIdAndSelf(String strParentId)
    '   {
    '       List<String> result = new List<string>();
    '       if (!result.Contains(strParentId))
    '       {
    '           result.Add(strParentId);
    '       }
    '       ADODB.Recordset rs = null;
    '       if (!String.IsNullOrEmpty(strParentId))
    '       {
    '           rs = ct.GetTable("select ID from XscBugType where ParentID='" + strParentId + "'");
    '       }
    '       else
    '       {
    '           rs = ct.GetTable("select ID from XscBugType where ParentID is null and type=4");
    '       }
    '       if (rs == null)
    '       {
    '           return null;
    '       }
    '       if (rs.EOF)
    '       {
    '           goto end1;
    '       }
    '       String str = "";
    '       String strid1 = "";
    '       while (!rs.EOF)
    '       {
    '           str = rs.Fields["ID"].Value.ToString();
    '           strid1 = rs.Fields["ID"].Value.ToString();
    '           if (!result.Contains(str))
    '           {
    '               result.Add(str);
    '           }
    '           String[] resultChid = GetChildIdAndSelf(strid1);
    '           if (null == resultChid)
    '           {
    '               goto end2;
    '           }
    '           foreach (String strItem in resultChid)
    '           {
    '               if (!result.Contains(strItem))
    '               {
    '                   result.Add(strItem);
    '               }
    '           }
    '       end2:
    '           rs.MoveNext();
    '       }
    '   end1:
    '       rs.Close();
    '       rs = null;
    '       return result.ToArray();
    '   }
#End Region

#Region "添加记录删除功能 A-2010-03-25"

    Public Function AddDeleteDetal(ByVal TableName As String, ByVal Keys() As String, ByVal values() As String, ByVal strUser As String) As Boolean
        If Keys.Length = 0 Then
            Return False
        End If

        If values.Length = 0 Then
            Return False
        End If

        'Dim strSql As String = "Insert into DeleteTable(TableName,key1,key2,key3,value1,value2,value3,UptTime,UserName) "
        'strSql = strSql & " values('@tablename','@column1','@column2','@column3','@value1','@value2','@value3','" + DateTime.Now.ToString() + "','" + strUser + "')"
        'strSql = strSql.Replace("@tablename", TableName)
        'strSql = strSql.Replace("@column1", Keys(0))
        'strSql = strSql.Replace("@column2", Keys(1))
        'strSql = strSql.Replace("@column3", Keys(2))
        'strSql = strSql.Replace("@value1", values(0))
        'strSql = strSql.Replace("@value2", values(1))
        'strSql = strSql.Replace("@value3", values(2))

        Dim strSql1 As String = "Insert into DeleteTable(TableName,key1,key2,key3,value1,value2,value3,UptTime,UserName)"
        strSql1 += " values(?,?,?,?,?,?,?,?,?)"
        Dim cmd As New ADODB.Command
        cmd.CommandText = strSql1
        Dim pa As ADODB.Parameter = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, TableName)
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, Keys(0))
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, Keys(1))
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, Keys(2))
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, values(0))
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, values(1))
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, values(2))
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, DateTime.Now.ToString())
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, strUser)
        cmd.Parameters.Append(pa)
        ExcCommand(cmd)

        Return True

    End Function
#End Region

#Region "添加记录删除图片和附件功能  A-2010-03-25"
    Public Function AddDeleteDetalImageUpload(ByVal strFileName As String, ByVal strUser As String) As Boolean

        Dim strSql1 As String = "Insert into DeleteImageUpdate(FileName,UptTime,UserName) values(?,?,?)"
        Dim cmd As New ADODB.Command
        cmd.CommandText = strSql1
        Dim pa As ADODB.Parameter = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 200, strFileName)
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, DateTime.Now.ToString())
        cmd.Parameters.Append(pa)
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, strUser)
        cmd.Parameters.Append(pa)
        ExcCommand(cmd)

        Return True

    End Function
#End Region

End Class


